package com.define.commons.common.converters;

import com.define.commons.common.serializer.DefaultValueSerializerModifier;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

/**
 * 全局消息转换器
 * @Author xiewenlong
 * @Date 2018/12/14 13:58
 */
@Configuration
public class GlobalMessageConvert {

    @Bean
    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(DefaultValueSerializerModifier defaultValueSerializerModifier){
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        converter.setSupportedMediaTypes(ImmutableList.of(MediaType.TEXT_HTML, MediaType.APPLICATION_JSON));
        ObjectMapper mapper = converter.getObjectMapper();
        mapper.setSerializerFactory(mapper.getSerializerFactory().withSerializerModifier(defaultValueSerializerModifier));
        return converter;
    }
}
